package cn.lhz.indiaCity.mysql

import cn.lhz.util.spark.SparkUtil
import org.apache.spark.sql.{SaveMode, SparkSession}

import java.util.Properties

/**
 * @author 年阔正
 * @version 1.0.0
 */

object fx01 {
  def main(args: Array[String]): Unit = {
    // 获取 SparkSession 对象
    val sparkSession: SparkSession = SparkUtil()

    // 同步分析结果到mysql
    import sparkSession.sql

    // 每个年龄段患有心血管疾病患者人数
    val df_all = sql("select * from air.dws_china")
    val properties: Properties = SparkUtil.mysqlConnectionProperties("air", "dws_china")
    val url: String = properties.getProperty("url")
    val tableName: String = properties.getProperty("tableName")
    df_all.printSchema() // 打印DataFrame模式
    df_all.write.mode(SaveMode.Overwrite).jdbc(url = url, table = tableName, connectionProperties = properties)

    sparkSession.stop()
  }

}
